package com.springcloud.order.controller;

import com.springcloud.model.base.Res.BaseRes;
import com.springcloud.model.entity.Order;
import com.springcloud.order.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author shengtao
 * @Description:
 * @date 2019/05/16 20:52
 */
@RestController
@Slf4j
public class OrderController {

    @Autowired
    private ProductService productService;

    @RequestMapping(method = RequestMethod.POST)
    public BaseRes save(Order order){
        order.setId("11014");
        return BaseRes.success(order);
    }

    @RequestMapping(value = "list",method = RequestMethod.GET)
    public BaseRes list(){
        List<Order> orders = new ArrayList<>();
        for (int i = 0 ; i< 10;i++){
            val or = Order.builder()
                    .id("10"+i)
                    .count(2+i)
                    .money(8.23F)
                    .price(2.3F)
                    .productId("1001")
                    .build();
            orders.add(or);
        }
        return BaseRes.success(orders);
    }

    @RequestMapping(method = RequestMethod.DELETE)
    public BaseRes delete(@RequestParam String orderId){
        return BaseRes.success(null);
    }

    @RequestMapping(method = RequestMethod.GET)
    public BaseRes get(){
        BaseRes res = productService.getName();
        log.info("<< trace-1 >>");
        return res;
    }

}
